package hutech.ksv.view;

import hutech.ksv.entity.NhaTroDataModel;
import hutech.ksv.entity.ThongTinNhaTroEntity;
import hutech.ksv.service.DuyetNhaTroService;

import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("request")
public class DuyetNhaTroManagedBean implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private NhaTroDataModel nhaTroDataModel;
	private List<ThongTinNhaTroEntity> selectedNhaTro;
	private List<ThongTinNhaTroEntity> danhSachThongNhaTro;
	public NhaTroDataModel getNhaTroDataModel() {
		return nhaTroDataModel;
	}
	public void setNhaTroDataModel(NhaTroDataModel nhaTroDataModel) {
		this.nhaTroDataModel = nhaTroDataModel;
	}
	public List<ThongTinNhaTroEntity> getSelectedNhaTro() {
		return selectedNhaTro;
	}
	public void setSelectedNhaTro(List<ThongTinNhaTroEntity> selectedNhaTro) {
		this.selectedNhaTro = selectedNhaTro;
	}
	public List<ThongTinNhaTroEntity> getDanhSachThongNhaTro() {
		return danhSachThongNhaTro;
	}
	public void setDanhSachThongNhaTro(
			List<ThongTinNhaTroEntity> danhSachThongNhaTro) {
		this.danhSachThongNhaTro = danhSachThongNhaTro;
	}
	
	@Autowired
	DuyetNhaTroService duyetNhaTroService;
	
	@PostConstruct
	public void init() {
		danhSachThongNhaTro = duyetNhaTroService.getTatCaThongTinNhaTro();
		nhaTroDataModel = new NhaTroDataModel(danhSachThongNhaTro);
	}
	
	public void onLoad() {
		selectedNhaTro = null;
		danhSachThongNhaTro = duyetNhaTroService.getTatCaThongTinNhaTro();
		nhaTroDataModel = new NhaTroDataModel(danhSachThongNhaTro);
	}
	
	public String duyetNhaTro() {
		for(ThongTinNhaTroEntity thongTinNhaTroEntity : selectedNhaTro) {
			duyetNhaTroService.duyetNhaTro(thongTinNhaTroEntity.getMaNT());
		}				
		return "duyetNhaTro";
	}

}
